#include "widget.h"
#include "ui_widget.h"

Widget::Widget(QWidget *parent)
    : QWidget(parent)
    , ui(new Ui::Widget)
{
    ui->setupUi(this);
}

Widget::~Widget()
{
    delete ui;
}



void Widget::on_btn_getCurrentDateTime_clicked()
{
    QDateTime currentDateTime = QDateTime::currentDateTime();

    ui->timeEdit->setTime(currentDateTime.time());
    ui->dateEdit->setDate(currentDateTime.date());
    ui->dateTimeEdit->setDateTime(currentDateTime);

    ui->lineEdit_time->setText(currentDateTime.toString("HH:mm:ss"));
    ui->lineEdit_date->setText(currentDateTime.toString("yyyy-MM-dd"));
    ui->lineEdit_time_date->setText(currentDateTime.toString("yyyy-MM-dd HH:mm:ss"));
}


void Widget::on_btn_set_time_date_clicked()
{
    QString text = ui->lineEdit_time_date->text();

    if(text.isEmpty())
        return;

    ui->dateTimeEdit->setDateTime(QDateTime::fromString(text,"yyyy-MM-dd HH:mm:ss"));
}


void Widget::on_btn_set_date_clicked()
{
    QString text = ui->lineEdit_date->text();

    if(text.isEmpty())
        return;

    ui->dateEdit->setDate(QDate::fromString(text,"yyyy-MM-dd"));
}

void Widget::on_btn_set_time_clicked()
{
    QString text = ui->lineEdit_time->text();

    if(text.isEmpty())
        return;

    ui->timeEdit->setTime(QTime::fromString(text,"HH:mm:ss"));
}


